package com.mrobuy.jdvc.dao.impl;

import com.mrobuy.jdvc.dao.VCSkuDao;
import com.mrobuy.jdvc.model.VCSku;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

@Repository("vcSkuDao")
public class VCSkuDaoImpl extends CommonDaoImpl implements VCSkuDao {

    private static Logger LOG = LoggerFactory.getLogger(VCSkuDao.class);

    @Override
    public List<VCSku> load(String wareId) {

        StringBuilder sql = new StringBuilder();
        sql.append("select pic.id, vc_item.WAREID, vc_item.SKUID,  vc_item.SKUNAME, vc_item.ITEMNUM, pic.TYPE, pic.ISPRIMARY, pic.POS, pic.URL   from vc_item left join  vc_item_pic pic   on pic.WAREID = vc_item.WAREID  where vc_item.WAREID = ? ");
        try {
            List<VCSku> list = getJdbcTemplate().query(sql.toString(), new Object[]{wareId}, new BeanPropertyRowMapper(VCSku.class));
            return list;
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }

        return Collections.EMPTY_LIST;

    }
}
